package pers.flowerinsnow.minecraft.forge.fastdungeonjoiner.manager

import net.minecraftforge.common.config.{ConfigCategory, Configuration}
import pers.flowerinsnow.minecraft.forge.fastdungeonjoiner.util.MessageUtils

import java.io.File

object ConfigManager {
  var file : File = _
  var config : Configuration = _
  def init(file : File): Unit = {
    this.file = file
    config = new Configuration(file)
    config.load()

    Config.load()
    Messages.load()
    config.save()
  }
  def reload(): Unit = {
    init(file)
  }
  def save(): Unit = {
    Config.save()
    Messages.save()

    config.save()
  }

  /**
   * Config分类
   */
  object Config {
    val category = "config"
    var fastdungeon : String = _
    def load(): Unit = {
      fastdungeon = config.get(category, "fastdungeon", "").getString
    }
    def save(): Unit = {
      config.get(category, "fastdungeon", "").set(fastdungeon)
    }
  }

  /**
   * Messages分类
   */
  object Messages {
    var category : String = "messages"
    var keybinding_openmenu_description : String = _
    var keybinding_fastdungeon_description : String = _
    var keybinding_fastdungeon_category : String = _

    var menugui_title : String = _
    var menugui_join : String = _
    var menugui_setdefault : String = _
    var menugui_cancelselect : String = _
    var fastjoin_notset : String = _
    var fastjoin_joining : String = _
    def load(): Unit = {
      keybinding_openmenu_description = config.get(category, "keybinding_openmenu_description", "打开菜单").getString
      keybinding_fastdungeon_description = config.get(category, "keybinding_fastdungeon_description", "一键进入地牢").getString
      keybinding_fastdungeon_category = config.get(category, "keybinding_fastdungeon_category", "FastDungeon快捷键").getString

      menugui_title = config.get(category, "menugui_title", "菜单 - FastDungeonJoiner").getString
      menugui_join = config.get(category, "menugui_join", "进入该层").getString
      menugui_setdefault = config.get(category, "menugui_setdefault", "设为默认").getString
      menugui_cancelselect = config.get(category, "menugui_cancelselect", "取消选择").getString

      fastjoin_notset = config.get(category, "fastjoin_notset", MessageUtils.parseColor("&7[&c×&7]&c清先设置您想进入的楼层 &e(*(KEY_BINDING) 键)")).getString
      fastjoin_joining = config.get(category, "fastjoin_joining", MessageUtils.parseColor("&7[&b!&7]&b正在尝试加入...")).getString
    }
    def save(): Unit = {
      config.get(category, "keybinding_openmenu_description", "打开菜单").set(keybinding_openmenu_description)
      config.get(category, "keybinding_fastdungeon_description", "一键进入地牢").set(keybinding_fastdungeon_description)
      config.get(category, "keybinding_fastdungeon_category", "FastDungeon快捷键").set(keybinding_fastdungeon_category)

      config.get(category, "menugui_title", "菜单 - FastDungeonJoiner").set(menugui_title)
      config.get(category, "menugui_join", "进入该层").set(menugui_join)
      config.get(category, "menugui_setdefault", "设为默认").set(menugui_setdefault)
      config.get(category, "menugui_cancelselect", "取消选择").set(menugui_cancelselect)

      config.get(category, "fastjoin_notset", MessageUtils.parseColor("&7[&c×&7]&c清先设置您想进入的楼层 &e(*(KEY_BINDING) 键")).set(fastjoin_notset)
      config.get(category, "fastjoin_joining", MessageUtils.parseColor("&7[&b!&7]&b正在尝试加入...")).set(fastjoin_joining)
    }
  }
}
